cloth(dresses, dress1, darkBlue, long, summer, pois,overall).
%cloth(dresses, dress4, darkBlue, long, summer, pois,overall).
%cloth(dresses, dress2, orange, short, summer, pois,overall).
%cloth(dresses, dress3, orange, short, summer, pois,overall).
cloth(shirt, shirt1, darkBlue, long, summer, pois,top).
cloth(jackets, jackets1, darkBlue, short, summer, pois,coat).
%cloth(jackets, jackets2, darkBlue, long, summer, pois,coat).
%cloth(trousers, troisers1, darkGreen, short, summer, pois,bottom).
%cloth(overcoats, ov2, orange, short, summer, pois,coat).
%cloth(shoes, shoes1, orange, short, summer, pois,footwear).
cloth(sportshoes, sport2, darkBlue, long, summer, pois,footwear).
cloth(blouses, blouses2, darkBlue, short, summer, pois,top).
cloth(sweater, sweater2, darkBlue, long, summer, pois,top).
%cloth(trousers, troisers1, darkGreen, short, summer, pois,bottom).

select(Category,Name,Color,Length,Season,Extra,Pos,Attr):-cloth(Category,Name,Color,Length,Season,Extra,Pos),Length\==Attr.
mmproduct(M,N,R):- findall([X,Y],(member(X,M),member(Y,N)),R).
exclude(Cat1,Attr1,Cat2,Attr2,R):-bagof(cloth(Cat1,Name,Color,Attr1,Season,Extra,Pos),cloth(Cat1,Name,Color,Attr1,Season,Extra,Pos),L1),
bagof(cloth(Cat2,Name,Color,Length,Season,Extra,Pos),select(Cat2,Name,Color,Length,Season,Extra,Pos,Attr2),L2),
mmproduct(L1,L2,R).

lista([cloth(A,B,C,D,E,F,overall),cloth(H,I,L,M,N,O,footwear),cloth(P,Q,R,S,T,U,top)]):- cloth(A,B,C,D,E,F,overall),
cloth(H,I,L,M,N,O,footwear),cloth(P,Q,R,S,T,U,coat).

sublist([H|T],L):- member(H,L), sublist(T,L).
sublist([],L).

deleteSubList([H|T],L,Z):- delete(H,L,FL), deleteSubList(T,FL,Z).
deleteSubList([],L,L).

risul(Z):- bagof(L,lista(L),New), exclude(dresses,long,jackets,long,R), sublist(R,L), deleteSubList(L,New,Z). 

%---------------------------------------



color_list(basic_dark_colors,[black, darkBlue, darkGrey, brown]).
color_list(basic_light_colors,[white, cream, camel, lightGray ]).

%chosen_categories=[dresses,shoes].

delete_sub_list([H|T],L,Z):- delete(H,L,FL), delete_sub_list(T,FL,Z).
delete_sub_list([],L,L).

delete_sub_list(L1,L2,L).

%exclude
category_filter_exclude([H|T]):- retract(cloth(H,_,_,_,_,_,_,)), category_filter_exclude(T).
%include _only
category_filter_include(L1,L2):- delete_sub_list(L1,L2,[H|T]), retract(cloth(H,_,_,_,_,_,_,)),  delete_sub_list(L1,L2,T).
%regola del tipo Attr is Value
first_selection(Category, Name, Color, Lenght, Season,Extra,Pos,[A|B],[C|D],[neg|F]):-
list(C),cloth(Category,Name,Color,Lenght,Season,Extra,Pos),member(A,C),
first_selection(Category, Name, Color, Lenght, Season,Extra,Pos,B,D,F).

first_selection(Category, Name, Color, Lenght, Season,Extra,Pos,[A|B],[C|D],[pos|F]):-
list(C),cloth(Category,Name,Color,Lenght,Season,Extra,Pos),not(member(A,C)),
first_selection(Category, Name, Color, Lenght, Season,Extra,Pos,B,D,F).

first_selection(Category, Name, Color, Lenght, Season,Extra,Pos,[A|B],[C|D],[neg|F]):-
color_list(X,Y),A==X ,cloth(Category,Name,Color,Lenght,Season,Extra,Pos),member(A,C),
first_selection(Category, Name, Color, Lenght, Season,Extra,Pos,B,D,F).

first_selection(Category, Name, Color, Lenght, Season,Extra,Pos,[A|B],[C|D],[pos|F]):-
color_list(X,Y),A==X ,cloth(Category,Name,Color,Lenght,Season,Extra,Pos),not(member(A,C)),
first_selection(Category, Name, Color, Lenght, Season,Extra,Pos,B,D,F).

first_selection(Category, Name, Color, Lenght, Season,Extra,Pos,[A|B],[C|D],[neg|F]):-
cloth(Category,Name,Color,Lenght,Season,Extra,Pos),A==C,
first_selection(Category, Name, Color, Lenght, Season,Extra,Pos,B,D,F).

first_selection(Category, Name, Color, Lenght, Season,Extra,Pos,[A|B],[C|D],[pos|F]):-
cloth(Category,Name,Color,Lenght,Season,Extra,Pos),A\==C,
first_selection(Category, Name, Color, Lenght, Season,Extra,Pos,B,D,F).

retractall(first_selection(Category, Name, Color, Lenght, Season,Extra,Pos,Attrs,Vals,Pols)).


if_selection([H|T], Name, Color, Lenght, Season,Extra,Pos,Attrs,Vals,Pols):- 
first_selection(H, Name, Color, Lenght, Season,Extra,Pos,Attrs,Vals,Pols), 
first_selection(T, Name, Color, Lenght, Season,Extra,Pos,Attrs,Vals,Pols).

mmproduct(M,N,R):- findall([X,Y],(member(X,M),member(Y,N)),R).

exclude(Cat1,Attr1,Cats,Attrs,Vals,Pols,R):-bagof(cloth(Cat1,Name,Color,Attr1,Season,Extra,Pos),
cloth(Cat1,Name,Color,Attr1,Season,Extra,Pos),L1),
bagof(cloth(Cat2,Name,Color,Length,Season,Extra,Pos),
if_selection(Cats, Name, Color, Lenght, Season,Extra,Pos,Attrs,Vals,Pols),L2),
mmproduct(L1,L2,R).

call_filter(Cat, Att, Val) :- condition(Cat, Att, Val), !, filter(Cat, Att).
call_filter(Cat, Att) :- filter_else(Cat, Att).

condition(dresses, length, short).
filter(desses, length, L):- ....
filter_else(dresses, length, L):- ...



retractList([]).
retractList([H|T]) :- retract(H), retractList(T).
retract(L).

mmproduct(M,N,R):- findall([X,Y],(member(X,M),member(Y,N)),R).
exclude(Cat1,Attr1,Cat2,Attr2,R):-bagof(cloth(Cat1,Name,Color,Attr1,Season,Extra,Pos),cloth(Cat1,Name,Color,Attr1,Season,Extra,Pos),L1),
bagof(cloth(Cat2,Name,Color,Length,Season,Extra,Pos),select(Cat2,Name,Color,Length,Season,Extra,Pos,Attr2),L2),
mmproduct(L1,L2,R).

lista([cloth(A,B,C,D,E,F,overall),cloth(H,I,L,M,N,O,footwear),cloth(P,Q,R,S,T,U,top)]):- 
	cloth(A,B,C,D,E,F,overall),cloth(H,I,L,M,N,O,footwear),cloth(P,Q,R,S,T,U,top).

risul(Z):- bagof(L,lista(L),New), exclude(dresses,long,jacket,long,R),
	   sublist(R,L), deleteSubList(L,New,Z). 





